package com.aoxon.cargo.shared;

import java.util.ArrayList;
import java.util.List;

import com.aoxon.cargo.bean.Supplier;
import com.aoxon.cargo.util.CurrentTimeUtil;
import com.google.gson.reflect.TypeToken;

/**
 * 商家收藏本地数据的保存
 * @author ZZJ
 *
 */
public class CollectSupplierShared extends MyShared {

	/**
	 * 获取商家收藏记录的列表数据
	 */
	public static List<Supplier> getColSupplierList() {
		List<Supplier> suppliers = new ArrayList<Supplier>();
		String strColSuppliers = sp.getString("SupplierCollection", "");
		System.out.println(strColSuppliers);
		if (!strColSuppliers.equals("")) {
			suppliers = gson.fromJson(strColSuppliers,
					new TypeToken<List<Supplier>>() {
					}.getType());
		}
		return suppliers;
	}

	/**
	 * 保存单个商家收藏记录数据
	 * @param supplier
	 */
	public static void saveColSupplier(Supplier supplier) {
		List<Supplier> suppliers = getColSupplierList();
		for (int i = 0; i < suppliers.size(); i++) {
			if (suppliers.get(i).getSupId() == supplier.getSupId()) {
				suppliers.remove(i);
			}
		}
		supplier.setSaveTime(CurrentTimeUtil.getCurrentTimeString());
		suppliers.add(supplier);
		saveDate("SupplierCollection", gson.toJson(suppliers));
	}

	/**
	 * 保存商家收藏记录的列表数据
	 * @param suppliers
	 */
	public static void saveColSupplierList(List<Supplier> suppliers) {
		saveDate("SupplierCollection", gson.toJson(suppliers));
	}
	
}
